/*/////////////////////////////////////////////////////////////////////////////////
/// An
///    ___   ____ ___ _____ ___  ____
///   / _ \ / ___|_ _|_   _/ _ \|  _ \
///  | | | | |  _ | |  | || | | | |_) |
///  | |_| | |_| || |  | || |_| |  _ <
///   \___/ \____|___| |_| \___/|_| \_\
///                              File
///
/// Copyright (c) 2008-2009 Ismail TARIM <ismail@royalspor.com> and the Ogitor Team
//
//This program is free software; you can redistribute it and/or modify it under
//the terms of the GNU Lesser General Public License as published by the Free Software
//Foundation; either version 2 of the License, or (at your option) any later
//version.
//
//This program is distributed in the hope that it will be useful, but WITHOUT
//ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
//FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
//You should have received a copy of the GNU Lesser General Public License along with
//this program; if not, write to the Free Software Foundation, Inc., 59 Temple
//Place - Suite 330, Boston, MA 02111-1307, USA, or go to
//http://www.gnu.org/copyleft/lesser.txt.
////////////////////////////////////////////////////////////////////////////////*/

#pragma once

namespace Ogitors
{
    //! Light visual helper class
    /* 
        This class encapsulates the visual appearance of light(s) in Ogitor.
    */
    class OgitorExport CLightVisualHelper : public CEntityVisualHelper
    {
    public:

        /**
        * Constructor
        */
        CLightVisualHelper(CBaseEditor *parent);
        /**
        * Destructor
        */
        virtual ~CLightVisualHelper();
        /**
        * Displays or hides light helper depending on the flag value
        * @param bShow flag to show/hide light helper
        */
        virtual void Show(bool bShow);
    private:

        /**
        * Creates point light for visual helper
        */
        void _createPointLight();

        /**
        * Creates directional light for visual helper
        */
        void _createDirectionalLight();

        /**
        * Creates spotlight for visual helper
        */
        void _createSpotLight();

        /**
        * Draws a circle around Z axis
        * @param radius circle radius
        * @param zOffset how far in to draw the circle on (for example, in directional light, the light has 'length' associated with arrow showing the direction)
        * @param colour circle' colour
        */
        void _drawCircle(const Ogre::Real radius, const Ogre::Real zOffset, const Ogre::ColourValue& colour);

        Ogre::Light::LightTypes mLightType;                     /** Type of the light */
        Ogre::ColourValue       mColour1;                       /** Primary colour */
        Ogre::ColourValue       mColour2;                       /** Secondary colour */
        Ogre::Radian            mSpotlightInnerAngle;           /** Spotlight inner angle value */
        Ogre::Radian            mSpotlightOuterAngle;           /** Spotlight outer angle value */
        Ogre::Real              mAttenuationRange;              /** Attennuation range */

        Ogre::Real              mDirectionalLightCircleRadius;  /** Directional light' circle radius */
        Ogre::Real              mDirectionalLightLength;        /** Directional light length (see _drawCircle) */
        Ogre::Real              mSpotlightStartCircleOffset;    /** The start offset of the spotlight */

        // this manual object represents our actual visual representation of the light depending 
        // on the given attributes
        Ogre::ManualObject*     mVisualHelperObject;            /** Handle to OGRE based manual object that represents camera */

        // scenemanager where our visual object belongs to
        Ogre::SceneManager*     mSceneManager;                  /** Handle of scene manager */

        // visual helper materials
        Ogre::MaterialPtr       mMaterial;                      /** Helper' material handle */

        // resource group of the internal material
        Ogre::String            mResourceGroup;                 /** Resource group for the light helper */

        OgitorsScopedConnection m_PropConnections[6];           /** Properties for light helper */

        /**
        * Delegate function that is called when diffuse value of the light is changed
        * @param value new diffuse value 
        */
        void OnDiffuseChange(Ogre::Any value);
        /**
        * Delegate function that is called when specular value of the light is changed
        * @param value new specular value 
        */
        void OnSpecularChange(Ogre::Any value);
        /**
        * Delegate function that is called when light type is changed
        * @param value new light type 
        */
        void OnLightTypeChange(Ogre::Any value);
        /**
        * Delegate function that is called when range of light is changed
        * @param value new light range
        */
        void OnRangeChange(Ogre::Any value);
        /**
        * Delegate function that is called when attennuation value of the light is changed
        * @param value new attennuation value 
        */
        void OnAttenuationChange(Ogre::Any value);
        /**
        * Delegate function that is called when visual helper is selected/deselected
        * @param value selection/deselection flag
        */
        void OnSelectionChange(Ogre::Any value);
    };
}